package com.sky.nacos.web;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.sky.nacos.entity.AccDetail;
import com.sky.nacos.service.IAccDetailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class NacosController {

    // 这里不能使用 @Value Value不能及时的更新内容  spring clod有一个@Refreshscope可以配置Value使用，数据能及时更新
    // 使用NacosValue的时候 autoRefreshed必须设置为true，否则也是会出现更新不及时问题
    @NacosValue(value = "${name:''}", autoRefreshed = true)
    //@Value("${name:''}")
    private String name;
    @Resource
    private IAccDetailService accDetailService;


    @GetMapping("/nacos")
    public String nacos(@RequestParam String accSn){
        System.out.println(accSn);
        System.out.println("name =========== " + name);
        AccDetail accDetail = accDetailService.select(accSn);
        return JSONObject.toJSONString(accDetail);
    }

}
